$(function(){
		/*初始化表格*/
		$('#sysOrg').datagrid({
    		url:'backsysorgjson',
    		collapsible:true,
    		fit:true,
			fitColumns:true,
			toolbar:'#footer',
			pagination:true,
			pageSize:20,
			pageList:[20,50,100,200],
			remoteSort:false,
   			columns:[[
   			 	{field:'ck',checkbox:true},
   			 	{field:'orgID',hidden:'true'},
				{field:'orgName',title:'公司名称',align:'center',width:'15%'},
				
				{field:'contact',title:'公司联系人',align:'center',width:'15%'},
				{field:'mobile',title:'联系手机号',align:'center',width:'15%'},
				{field:'tel',title:'联系电话',align:'center',width:'15%'},
				{field:'upOrgName',title:'上级所属公司',align:'center',width:'15%'},
				{field:'memo',title:'备注',align:'center',width:'23%'}
    		]]
		});
			
});

/*搜索*/
function searchOrg(){
	
		var orgName = $("#orgName").val();
		var upOrgID = $("#upOrgID").val();
		var zoneID = $("#zoneID").val();
		$("#sysOrg").datagrid("load",{
			orgName:orgName,
			upOrgID:upOrgID,
			zoneID:zoneID
		})
	}
	
/*清空*/
function clearOrg(){
        $("#orgName").val('');
	 $("#upOrgID").val('');
 $("#orgZoneID").val('');
 $("#orgCityID").val('');
 $("#zoneID").val('');
     }
//后台	招标新建与修改时正则验证 2020.11.19
function orgSubmit(orgForm){
if(!(/^1[3456789]\d{9}$/.test(orgForm.Mobile.value))){ 
		$.messager.alert('错误','联系人手机号格式错误！','error');
	$("#OrgMobile").focus();
	return false;	
    } 
if(orgForm.Tel.value!=""){
if(!(/^\d{3}-\d{7,8}|\d{4}-\d{7,8}$/.test(orgForm.Tel.value))){ 
$.messager.alert('错误','联系人固定电话号码格式错误！','error');
	orgForm.Tel.focus();
		
	return false;	
    }
}
if(!(orgForm.Fax.value=="")){
if(!(/^(?:\d{3,4}-)?\d{7,8}(?:-\d{1,6})?$/ .test(orgForm.Fax.value))){ 
$.messager.alert('错误','公司传真格式错误！','error');
	orgForm.Fax.focus();
		
	return false;	
    }
}
	}
	
	/* 修改同业信息 */
	function updateSysOrg(){
		
		
		var rows = $('#sysOrg').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else if(checkNum>1){
			$.messager.alert('错误','最多选择一项','error');
		 }else{
		$.messager.confirm('Confirm', '确定要修改吗?', function(r){
	if (r){
		var iOrgID = rows[0].orgID; 
		 	location.href="/mmy/backtoupdateorg?iOrgID="+iOrgID;
	}
});	
}
		
}
/* 修改同业信息 */
	function delSysOrg(){
		
		
		var rows = $('#sysOrg').datagrid('getSelections');
		var checkNum = rows.length;
		if(checkNum==0){
			$.messager.alert('错误','至少选择一项','error');
		 } else{
			var checklist = new Array();
			var checkName = [];
			checkName.push('将要删除以下公司:');
			for(var i=0; i<rows.length; i++){
				
				checklist.push(rows[i].orgID);
				checkName.push('<span>'+rows[i].orgName +'</span>');
			}
			$.messager.confirm('提示',checkName, function(r){
    		if (r){
				$.ajax({
			        url:"/mmy/backdeleteorgchecked",
			        type:"post",
			        data:{
			            checkList:checklist.toString()
			        },
			        dataType:"json",
			       success:function (data) {
	var lstSucc=data.successOrg;
	var lstFail=data.failOrg;
						 $("#sysOrg").datagrid("reload");
					if(lstSucc.length==0){
					$.messager.show({title:'消息',msg:lstFail+'不可删除',timeout:3000,});	
					}
					if(lstFail.length==0){
						$.messager.show({title:'消息',msg:lstSucc+'删除成功',timeout:3000,});
					}
					if(lstSucc.length>0 && lstFail.length>0)
			             $.messager.show({title:'消息',msg:lstSucc+'删除成功,'+lstFail+'不可删除',timeout:3000,});

					},
			        error:function () {
			           $.messager.show({title:'消息',msg:'删除失败',timeout:3000,});
			        }
			    })
    		}
		});		
	}		
}



